package com.lw.common.customview.item_decoration

import android.content.Context
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.luck.picture.lib.utils.DensityUtil

/**
 * @description:列表 条目之间的间距
 * @author: yuan
 * @date: 2024/12/16
 */
class ItemDecoration : RecyclerView.ItemDecoration {
    private val px: Int

    constructor(px: Int) {
        this.px = px
    }

    constructor(context: Context, dp: Int) {
        this.px = DensityUtil.dip2px(context, dp.toFloat())
    }

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        super.getItemOffsets(outRect, view, parent, state)
        val childAdapterPosition = parent.getChildAdapterPosition(view)
        outRect.bottom = px
        outRect.left = px
        outRect.right = px
        //        if (childAdapterPosition == 0) {
//            outRect.top = px;
//        }
    }
}
